<?php

class Upload extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        $this->load->model('m_giaodien');
    }

    function index() {
        $this->load->view('upload_form', array('error' => ' '));
    }
    
    
    
    
    
    
    
    function header_upload() {
        $config['upload_path'] = './assets/imgs/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '2000';
        $config['max_height'] = '2000';

        $this->load->library('upload', $config);
        echo 'pre up';
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            echo 'error';
            $this->load->view('test', $error);
        } else {
            $upload_data = $this->upload->data();
//
            $HinhAnh = 'imgs/' . $upload_data['file_name'];

            $data = array(
                'Value_element' => $HinhAnh,
            );
            print_r($data);
//            echo 'pass pre-update';
            if ($this->m_giaodien->updateImage(1, $data))
                redirect('/test', 'refresh');
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    function do_upload() {

        $config['upload_path'] = './assets/imgs/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '2000';
        $config['max_height'] = '2000';

        $this->load->library('upload', $config);
        echo 'pre up';
        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());
            echo 'error';
            //  $this->load->view('test', $error);
        } else {
            echo 'pass up';


            // $this->load->view('upload_success', $data);
//            
            $upload_data = $this->upload->data();
//
            $HinhAnh = 'imgs/' . $upload_data['file_name'];
            echo $HinhAnh;
            $data = array(
                'Value_element' => $HinhAnh,
            );
            print_r($data);
//            echo 'pass pre-update';
            if ($this->m_giaodien->updateImage(1, $data))
                echo 'finish';
        }
    }

    function do_upload1() {
        $config['upload_path'] = './assets/imgs/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '1366';
        $config['max_height'] = '768';

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());

            $this->load->view('upload_form', $error);
        } else {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }
    }

}

?>